package threadPoolTest;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @SchedulThreadPool: 定长线程池 可执行周期性任务
 * @author: ZBoHang
 * @time: 2021/9/6 17:26
 */
public class ScheduledThreadPool {

    static ScheduledExecutorService scheduledExecu = Executors.newScheduledThreadPool(4);

    public static void main(String[] args) {
        test();
    }

    private static void test() {
        for (int i = 0; i < 6; i++) {
            final int index = i;
            scheduledExecu.scheduleWithFixedDelay(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName() + " index--> " + index);
                }
            }, 0, 3, TimeUnit.SECONDS);
        }
    }
}













